package com.sdcqjy.property.activity;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;

import com.sdcqjy.property.R;
import com.sdcqjy.property.adapter.SutraCaseAdapter;
import com.sdcqjy.property.base.SimpleBaseActivity;
import com.sdcqjy.property.mode.ListGroupMode;
import com.sdcqjy.property.mode.ListMsgMode;
import com.sdcqjy.property.presenter.SutraCasePresenter;
import com.sdcqjy.property.presenter.contract.SutraCaseContract;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by 磁磁帅 on 2018/4/19.
 * 功能：经典案例分析 模板
 */
public class TemplActivity extends SimpleBaseActivity<SutraCasePresenter> implements SutraCaseContract.View {
    @BindView(R.id.listView)
    ExpandableListView listView;
    @BindView(R.id.layoutBott)
    View layoutBott;
    @BindView(R.id.imgBack)
    View imgBack;
    private ListGroupMode mode1, mode2;//, mode3;
    private List<ListGroupMode> modeList;
    private SutraCaseAdapter adapter;

    public static void open(Context context) {
        Intent intent = new Intent(context, TemplActivity.class);
        context.startActivity(intent);
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sutra_case);
        ButterKnife.bind(this);
        presenter = new SutraCasePresenter(this);
        Resources res = getResources();
        mode1 = new ListGroupMode(R.mipmap.img_group1, res.getString(R.string.cgqlmb));
        mode2 = new ListGroupMode(R.mipmap.img_group2, res.getString(R.string.zzlmb));
        //mode3 = new ListGroupMode(R.mipmap.img_group3, res.getString(R.string.zclmb));
        modeList = new ArrayList<>();
        modeList.add(mode1);
        modeList.add(mode2);
        //modeList.add(mode3);
        adapter = new SutraCaseAdapter(getActivity(), modeList);
        listView.setAdapter(adapter);

        layoutBott.setVisibility(View.GONE);
        imgBack.setVisibility(View.VISIBLE);
    }

    protected void asynRun() {
        openLoadDialog();
        presenter.getList(12);
        presenter.getList(13);
        //presenter.getList(14);
    }

    public void getListRet(int type, List<ListMsgMode> data) {
        switch (type) {
            case 12:
                mode1.modeList = data;
                break;
            case 13:
                mode2.modeList = data;
                break;
            case 14:
                //mode3.modeList = data;
                break;
        }
        adapter.notifyDataSetChanged();
        listView.postDelayed(this::openAll, 100);
    }

    private void openAll() {
        int groupCount = listView.getCount();
        for (int i = 0; i < groupCount; i++) {
            listView.expandGroup(i);
        }
    }
}
